package com.scholarship.common.config;

import org.apache.ibatis.session.ResultContext;
import org.apache.ibatis.session.ResultHandler;

import java.util.HashMap;
import java.util.Map;

/**
 * 实现org.apache.ibatis.session.ResultHandler
 * 用于转化数据集为Map
 * @Author Z.J.H
 * @create 2021/9/11 19:31
 */
public class MapResultHandler implements ResultHandler {

    private final Map mappedResults = new HashMap();

    public Map getMappedResults() {
        return mappedResults;
    }

    @Override
    public void handleResult(ResultContext resultContext) {
        Map map = (Map) resultContext.getResultObject();

        //xml配置里面的property的值，对应的列
        mappedResults.put(map.get("key"),map.get("value"));
    }
}
